package org.itboys.baseobject.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.itboys.baseobject.service.CityService;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * 省市县镇街道控制层
 * @author weisky
 *
 */
@RestController 
@RequestMapping("/city") 
public class CityController extends BaseController{

	@Autowired
	private CityService cityService;
	
	/**
	 * 获取所有的省份
	 * @return
	 */
	@RequestMapping("/findAllProvince")
	public void findAllProvince(HttpServletRequest request , HttpServletResponse response){
		AjaxUtils.renderJson(response, cityService.findAllProvince());
	}
	
	/**
	 * 获取省份下的所有市区
	 * @param provinceId
	 * @return
	 */
	@RequestMapping("/findAllCity")
	public void findAllCity(@RequestParam("provinceId") long provinceId,
			HttpServletRequest request , HttpServletResponse response){
		AjaxUtils.renderJson(response, cityService.findAllCity(provinceId));
	}
	
	/**
	 * 获取所有市下的县/区
	 * @param cityId
	 * @return
	 */
	@RequestMapping("/findAllcounty")
	public void findAllcounty(@RequestParam("cityId") long cityId,
			HttpServletRequest request , HttpServletResponse response){
		AjaxUtils.renderJson(response, cityService.findAllcounty(cityId));
	}
	
	/**
	 * 获取县/区下的所有镇/街道
	 * @param countyId
	 * @return
	 */
	@RequestMapping("/findAllTown")
	public void findAllTown(@RequestParam("cityId") long countyId,
			HttpServletRequest request , HttpServletResponse response){
		AjaxUtils.renderJson(response, cityService.findAllTown(countyId));
	} 
}
